<?php

namespace Test\Unit;

use Design\Creational\Pool\WorkerPool;
use Design\Creational\Pool\StringReverseWorker;

class PoolTest extends \Test\BaseTest
{


    public function testCanInstanceWorker()
    {
        $pool    = new WorkerPool();
        $worker1 = $pool->get();
        $worker2 = $pool->get();

        $this->assertInstanceOf(StringReverseWorker::class, $worker1);
        $this->assertCount(2, $pool);
        $this->assertNotSame($worker1, $worker2);

    }//end testCanInstanceWorker()


    public function testCanGetSameInstanceWithDisposeFirst()
    {
        $pool    = new WorkerPool();
        $worker1 = $pool->get();
        $pool->dispose($worker1);
        $worker2 = $pool->get();
        $this->assertCount(1, $pool);
        $this->assertSame($worker1, $worker2);

    }//end testCanGetSameInstanceWithDisposeFirst()


    public function testCanReverseText()
    {
        $pool   = new WorkerPool();
        $worker = $pool->get();

        $this->assertSame('321', $worker->run('123'));

    }//end testCanReverseText()


}//end class
